using System.Windows;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace WIAssistant
{
    /// <summary>
    /// Used to define the default title for a work item type.
    /// </summary>
    public class WITSelectorNode:INotifyPropertyChanged
    {
        public String WorkItemTypeName { get; set; }
        public List<String> AllFieldsForWorkItemType { get; set; }
        private String _defaultFieldName;
        public String DefaultFieldName
        {
            get { return _defaultFieldName; }
            set
            {
                _defaultFieldName = value;
                OnPropertyChanged("DefaultFieldName");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public void UpdateFieldList(WorkItemType wiType)
        {
            AllFieldsForWorkItemType.Clear();
            foreach (FieldDefinition definition in wiType.FieldDefinitions)
            {
                AllFieldsForWorkItemType.Add(definition.Name);
            }
            AllFieldsForWorkItemType.Sort();
        }
    }
}